<!--
 * @Author: your name
 * @Date: 2020-09-25 20:36:46
 * @LastEditTime: 2020-09-25 22:19:03
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \Briup\8-\web\pages\commentManager.html
-->
<!-- 评论管理页面 -->


<div class="row">
    <div><label for="exampleInputName2">审核状态</label></div>
    <div> <select name="" id="" class="form-control">
      <option value="">请选择</option>
    </select></div>
    <div>
        <div><input id="message_name" type="text" class="form-control" placeholder="请输入关键字"></div>
    </div>
    <div><button id="comment_search" class="btn btn-primary">搜索</button></div>

</div>
<table class="table table-hover" id="comment_table">
    <thead>
        <td><input type="checkbox"></td>
        <td>序号</td>
        <td>评论内容</td>
        <td>评论日期</td>
        <td>状态</td>
        <td>操作</td>
    </thead>
    <tbody></tbody>
</table>

<!-- 分页代码 -->
<nav aria-label="Page navigation">
    <ul class="pagination">
        <li class="currentnum">
            <a href="#" aria-label="Previous">
                <span aria-hidden="true">&laquo;</span>
            </a>
        </li>

        <li>
            <a href="#" aria-label="Next">
                <span aria-hidden="true">&raquo;</span>
            </a>
        </li>
    </ul>
</nav>


<script>
    var page = 1; //设置起始页
    var pageSize = 10; //设置每页信息数量
    $.get(baseURL + '/comment/pageQuery', {
        page,
        pageSize
    }, function(res) {
        // console.log(res);
        //清空tbody
        $('#comment_table tbody').empty();
        res.data.list.forEach(function(item, index) {
                //item-->每个用户对象
                var newTr = $(`                    
                    <tr>
                        <td><input type="checkbox" value="${item.id}"></td>
                        <td>${index + 1}</td>
                        <td>${item.content}</td>
                        <td>` + new Date(item.commentTime).toLocaleString() + `</td>
                        <td>${item.status}</td>
                        <td>
                          <button data-id="${item.id}" class="btn btn-danger" id="comment_delete">删除</button>
                          <button data-status="${item.status}" class="btn btn-success" id="comment_pass'">通过</button>
                          <button data-status="${item.status}" class="btn btn-warning " id="comment_nopass'">不通过</button>
                        </td>
                    </tr>`);
                $('#comment_table tbody').append(newTr)
            })
            //清空分页,再插入分页
        if ($(".clicknum.length") > 0) {
            $(".clicknum").remove();
        }
        var num = Math.ceil(res.data.total / pageSize);
        // alert(num)
        for (var i = num; i > 0; i--) {
            $('.currentnum').after(
                '<li class="clicknum"><a href="#">' + i + '</a></li>')
        }
    });
    var status = $(this).attr('data-status');
    // alert(status)
    // console.log(status);
    if (status == '审核通过') {
        // alert()
        $('#comment_pass').attr("disabled", 'disabled')
    } else if (status == "审核未通过") {
        // alert(2)
        $('#comment_nopass').attr("disabled", 'disabled')
    }
</script>